const SCHEME = "fps";
const CLASSNAME = "FPS";
const CONTRACTID = "@mozilla.org/network/protocol;1?name=" + SCHEME;
const CID = Components.ID("db156d4b-c27d-11dc-a373-001b210f913f");

function Protocol()
{
}

Protocol.prototype =
{
    scheme: SCHEME,
    defaultPort: -1,
    protocolFlags: Components.interfaces.nsIProtocolHandler.URI_NORELATIVE | Components.interfaces.nsIProtocolHandler.URI_NOAUTH,
    QueryInterface: function(iid)
    {
        if (!iid.equals(Components.interfaces.nsIProtocolHandler) && !iid.equals(Components.interfaces.nsISupports)) throw Components.results.NS_ERROR_NO_INTERFACE;
        return this;
    },
    allowPort: function(port, scheme)
    {
        return false;
    },
    newURI: function(spec, charset, baseURI)
    {
        var uri = Components.classes["@mozilla.org/network/simple-uri;1"].createInstance(Components.interfaces.nsIURI);
        uri.spec = spec;
        return uri;
    },
    newChannel: function(aURI)
    {
        var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
        var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
        observerService.notifyObservers(null, "ellaunch-launch-request", aURI.spec);
        return ios.newChannel("about:blank", null, null);
    }
}

var Module = new Object();

Module.registerSelf = function (compMgr, fileSpec, location, type)
{
    compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
    compMgr.registerFactoryLocation(CID,
                                  CLASSNAME,
                                  CONTRACTID,
                                  fileSpec,
                                  location,
                                  type);
}

Module.getClassObject = function (compMgr, cid, iid)
{
    if (!cid.equals(CID)) throw Components.results.NS_ERROR_NO_INTERFACE;
    if (!iid.equals(Components.interfaces.nsIFactory)) throw Components.results.NS_ERROR_NOT_IMPLEMENTED;

    return Factory;
}

Module.canUnload = function (compMgr)
{
    return true;
}

var Factory = new Object();

Factory.createInstance = function (outer, iid)
{
    if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;

    if (!iid.equals(Components.interfaces.nsIProtocolHandler) && !iid.equals(Components.interfaces.nsISupports)) throw Components.results.NS_ERROR_NO_INTERFACE;
    return new Protocol();
}

function NSGetModule()
{
    return Module;
}
